<script type="text/javascript">
$(function(){
	var pg = App.batch.infoIndex.ui, pp = pg.params,
		catalogLb = pg.find('.info>.head').seek('title');
	
	var gd = pg.find('.grid').mac('grid', {
		key: 'id',
		cols: [{
			field: 'catalog', title : '所属系统', width: 160, 
			render: function(r, tr, me){
				return $('<span class="a"></span>').click(function(){
					catalogLb.text(r.catalog);
					me.load({ catalog: r.catalog, pageNo: 1, key: '' });
				}).append(r.catalog);
			}
		}, {
			field: 'code', title : '编号', width: 200,
			render: function(r, tr, me){
				return $('<span class="a"></span>').click(function(){
					var p = pg.parent();
					if (App.logon.power('batch.info.save')){
						App.show({
							title: '批量信息',
							ctx: 'batch',
							action: 'infoEdit',
							params: r
						}, function(r, s){
							App.show({
								ctx : 'batch',
								action : 'infoIndex',
								params : {}
							}, $.noop, p);
						}, p);
					}
				}).append(r.code);
			}
		}, {
			field: 'name', title : '名称 ', width: 240
		},{
			field: 'status', title : '状态', width: 80,
			render: function(r) {
				return Cache.batch.info.status[r.status];
			}
		},{
			field: 'exec', title : '执行记录', width: 80,
			render: function(r) {
				return $('<span class="a">点击查看</span>').click(function(){
					App.show({
						title: '批量执行记录',
						ctx: 'batch',
						action: 'executionIndex',
						params: r
					}, $.noop, pg.parent());
				});
			}
		},{
			field: 'id', title : '操作', width: 120,
			render: function(r, tr, gd) {
				var p = $('<div></div>'), v = r.status,
					aa = ['enable', 'disable'], la = ['激活','停用'],
					st = '<span class="a"></span>';
				if (App.logon.power('batch.info.enable')
						&& App.logon.power('batch.info.disable')) {
					$(st).click(function(){
						mac.confirm('确定要 ' + la[v] + ' 批量 ' + r.code + ' 吗？', function(){
							$.post(App.ctx + '/info/' + aa[r.status] + '.do', {
								id: r.id,
							}, function(rs){
								var ro = mac.eval(rs);
								if (ro.success) {
									gd.load();
								} else {
									mac.alert(ro.data, ro.params);
								}
							});
						});
					}).append(la[v]).appendTo(p);
				}
				if (App.logon.power('batch.info.start')) {
					p.append('&nbsp;');
					$(st).click(function(){
						mac.confirm('确定要 调起 批量 ' + r.code + ' 吗？', function(){
							$.post(App.ctx + '/info/start.do', {
								id: r.id,
							}, function(rs){
								var ro = mac.eval(rs);
								if (ro.success) {
									gd.load();
								} else {
									mac.alert(ro.data, ro.params);
								}
							});
						});
					}).append('执行').appendTo(p);
				}
				if (r.status == 0 && App.logon.power('batch.info.delete')) {
					p.append('&nbsp;');
					$(st).click(function(){
						mac.confirm('确定要 删除 批量 ' + r.code + ' 吗？', function(){
							$.post(App.ctx + '/info/delete.do', {
								id: r.id,
							}, function(rs){
								var ro = mac.eval(rs);
								if (ro.success) {
									gd.load();
								} else {
									mac.alert(ro.data, ro.params);
								}
							});
						});
					}).append('删除').appendTo(p);
				}
				return p;
			}
		}],
		loader: {
			url: App.ctx + '/info/list.do',
			params: {
				pageNo: 1, pageSize: 10
			},
			autoLoad: true
		},
		pagerLength: 10
	});
	
	pg.seek('key').keydown(function(e) {
		if (e.keyCode == 13) {
			gd.load({ key : $(this).val() });
		}
	});
	pg.seek('back').click(function(){
		catalogLb.text('全部批量');
		gd.load({ catalog: '', pageNo: 1, key: '' });
	});
	if (App.logon.power('batch.info.save')) {
		pg.seek('create').click(function(){
			var p = pg.parent();
			App.show({
				title: '批量信息',
				ctx: 'batch',
				action: 'infoEdit',
				params: { status: 0 }
			}, function(r, s){
				App.show({
					ctx: 'batch',
					action: 'infoIndex'
				}, $.noop, p);
			}, p).show();
		}).show();
	}
	
	function adjust(){
		var p = pg.parent(), w = p.width(), h = p.height();
		pg.width(w - 64);
		gd.parent().height(h - 96);
		gd.adjust();
	}
	$(window).resize(adjust);
	adjust();
});
</script>
<div class="navi">
	<span class="a" name="back">批量列表</span>&gt;&gt;
	<span name="title">全部批量</span>
</div>
<div class="head">
	<button name="create" class="hidden">创建</button>
	&nbsp;&nbsp;&nbsp;&nbsp;
	<input type="text" name="key" placeholder="查找" />
</div>
<div class="body">
	<div class="grid"></div>
</div>